﻿using K9Nano.Enums;

namespace K9Nano.Settings;

public class SettingDefinition
{
    /// <summary>
    /// Unique name of the setting.
    /// </summary>
    public string Name { get; private set; }

    /// <summary>
    /// Display name of the setting.
    /// This can be used to show setting to the user.
    /// </summary>
    public string? DisplayName { get; set; }

    /// <summary>
    /// A brief description for this setting.
    /// </summary>
    public string? Description { get; set; }

    /// <summary>
    /// Default value of the setting.
    /// </summary>
    public string? DefaultValue { get; set; }

    /// <summary>
    /// Can be used to store a custom object related to this setting.
    /// </summary>
    public object? CustomData { get; set; }

    /// <summary>
    /// 若非空，作为设置值的选项: Key - Label, value - Value
    /// </summary>
    public IReadOnlyList<KeyValuePair<string, string>>? Options { get; set; }

    /// <summary>
    /// 作用域
    /// </summary>
    public ESettingScope Scope { get; set; }

    /// <summary>
    /// Creates a new <see cref="SettingDefinition"/> object.
    /// </summary>
    /// <param name="name">Unique name of the setting</param>
    /// <param name="defaultValue">Default value of the setting</param>
    /// <param name="displayName">Display name of the permission</param>
    /// <param name="description">A brief description for this setting</param>
    /// <param name="customData">Can be used to store a custom object related to this setting</param>
    /// <param name="options">若非空，作为设置值的选项: Key - Label, value - Value</param>
    public SettingDefinition(
        string name,
        string defaultValue,
        string? displayName = null,
        string? description = null,
        object? customData = null,
        IReadOnlyList<KeyValuePair<string, string>>? options = null,
        ESettingScope scope = default)
    {
        if (string.IsNullOrEmpty(name))
        {
            throw new ArgumentNullException(nameof(name));
        }

        Name = name;
        DefaultValue = defaultValue;
        DisplayName = displayName;
        Description = description;
        CustomData = customData;
        Options = options;
        Scope = scope;
    }
}